# -*- coding: utf-8 -*-
"""
@Time ： 2024/6/26 14:17
@Auth ： 九问
@File ：ronglianyun.py
@IDE ：PyCharm
@Email : 2750826557@qq.com
"""
import json

from ronglian_sms_sdk import SmsSDK

from config.ronglianyun.ronglianyunConfig import accId, accToken, appId


class Message:
    # 单例模式
    def __new__(cls, *args, **kwargs):
        # 如果是第一次创建对象，应该返回创建成功之后的对象，如果是第二次创建对象，应该返回上一次创建的对象
        if not hasattr(cls, '_instance'):
            # 给类加上私有属性
            cls._instance = super().__new__(cls, *args, **kwargs)
            cls._instance.sdk = SmsSDK(accId, accToken, appId)
        return cls._instance

    def send_message(self, mobile, datas):
        sdk = self.sdk
        tid = '1'
        resp = sdk.sendMessage(tid, mobile, datas)
        resp = json.loads(resp)
        if resp['statusCode'] == '000000':
            return 0
        else:
            return 1


if __name__ == '__main__':
    m = Message()
    m.send_message('13272631958', ('8787', '5'))  # datas为验证码和过期时间
